import { NextRequest, NextResponse } from 'next/server';

export async function GET(request: NextRequest) {
  try {
    // 检查请求头
    const authHeader = request.headers.get('authorization');
    
    // 返回详细的授权信息
    return NextResponse.json({
      hasAuthHeader: !!authHeader,
      authHeaderFormat: authHeader ? (authHeader.startsWith('Bearer ') ? '正确' : '错误') : '无',
      tokenPreview: authHeader && authHeader.startsWith('Bearer ') 
        ? authHeader.split(' ')[1].substring(0, 20) + '...' 
        : '无',
      cookies: Object.fromEntries(request.cookies.getAll().map(c => [c.name, c.value])),
      timestamp: new Date().toISOString()
    });
    
  } catch (error) {
    console.error('检查授权错误:', error);
    return NextResponse.json(
      { error: '检查授权失败', details: error instanceof Error ? error.message : '未知错误' },
      { status: 500 }
    );
  }
}
